package day5;

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int size = sc.nextInt();
        int[] array = new int[size];
        for(int i = 0; i< size;i++) {
             array[i] = sc.nextInt();
        } 
        int[] dp =new int[size];
        dp[0]=array[0];
        int max=dp[0];
        for(int i=1;i<size;i++){
            dp[i]=Math.max(dp[i-1]+array[i],array[i]);
            max=Math.max(max,dp[i]);
        }
        System.out.println(max);

        
    }
}